// 自定义Vite插件 - 用于抑制Sass弃用警告
module.exports = function suppressSassWarnings() {
  let originalConsoleWarn;
  
  return {
    name: 'suppress-sass-warnings',
    configureServer(server) {
      // 拦截警告输出
      originalConsoleWarn = console.warn;
      
      console.warn = function(message, ...args) {
        // 过滤掉Sass的@import弃用警告
        if (typeof message === 'string' && (
          message.includes('Sass @import rules are deprecated') ||
          message.includes('tint() function is deprecated') ||
          message.includes('The legacy JS API is deprecated')
        )) {
          return;
        }
        
        // 其他警告正常显示
        originalConsoleWarn.apply(console, [message, ...args]);
      };
      
      // 服务器关闭时恢复原始console.warn
      server.httpServer.on('close', () => {
        if (originalConsoleWarn) {
          console.warn = originalConsoleWarn;
        }
      });
    },
    // 在构建过程中也应用相同的逻辑
    buildStart() {
      originalConsoleWarn = console.warn;
      
      console.warn = function(message, ...args) {
        if (typeof message === 'string' && (
          message.includes('Sass @import rules are deprecated') ||
          message.includes('tint() function is deprecated') ||
          message.includes('The legacy JS API is deprecated')
        )) {
          return;
        }
        
        originalConsoleWarn.apply(console, [message, ...args]);
      };
    },
    buildEnd() {
      // 恢复原始console.warn
      if (originalConsoleWarn) {
        console.warn = originalConsoleWarn;
      }
    }
  };
};